import JJAPPConfig from './../resource/file/appConfig/JJAPPConfig'
import JJService from './../service/JJService'

export default class JJStorage {

    // otherInfo：key storageMethod, value: local、session、applicationCache、webSql
    static get(key, isForAllAccount = false, otherInfo = {storageMethod: 'local'}) {
        if (JJAPPConfig.isAppParasitifer()) {
            return JJService.customCacheObject(key, isForAllAccount)
        } else if (JJAPPConfig.isH5Parasitifer()) {
            const storageMethod = otherInfo.storageMethod
            if (storageMethod == 'local') {
                return localStorage.getItem(key)
            } else if (storageMethod == 'session') {
                return sessionStorage.getItem(key)
            }
        }
    }

    static set(key, value, isForAllAccount = false, otherInfo = {storageMethod: 'local'}) {
        if (JJAPPConfig.isAppParasitifer()) {
            return JJService.saveCustomCacheObject(key, value, isForAllAccount)
        } else if (JJAPPConfig.isH5Parasitifer()) {
            const storageMethod = otherInfo.storageMethod
            if (storageMethod == 'local') {
                return localStorage.setItem(key, value)
            } else if (storageMethod == 'session') {
                return sessionStorage.setItem(key, value)
            }
        }
    } 

    static remove(key, isForAllAccount = false, otherInfo = {storageMethod: 'local'}) {
        if (JJAPPConfig.isAppParasitifer()) {
            return JJService.removeCustomCacheObject(key, isForAllAccount)
        } else if (JJAPPConfig.isH5Parasitifer()) {
            const storageMethod = otherInfo.storageMethod
            if (storageMethod == 'local') {
                return localStorage.removeItem(key)
            } else if (storageMethod == 'session') {
                return sessionStorage.removeItem(key)
            }
        }
    } 
}
